package com.qdlc.p2p.biz.processor.task;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.qdlc.p2p.biz.processor.event.QueueLogValueEvent;
import com.qdlc.p2p.common.core.queue.TaskProcessorException;
import com.qdlc.p2p.common.core.queue.ValueEvent;
import com.qdlc.p2p.dal.dao.QueueLogDao;
import com.qdlc.p2p.dal.dto.QueueLog;


/**
 * PS 队列处理
 *
 * @author wuaj
 */
@Service
public class QueueLogProcessor extends AbstractTaskProcessor {

    @Resource
    private QueueLogDao queueLogDao;

    @Override
    public boolean supports(ValueEvent event) {
        return event instanceof QueueLogValueEvent;
    }

    @Override
    public void process0(ValueEvent event) throws TaskProcessorException {
        QueueLogValueEvent queueLogValueEvent = (QueueLogValueEvent) event;
        QueueLog queueLog = queueLogValueEvent.getQueueLog();
        if (queueLog == null) return;
        if (queueLog.getId() > 0) {
            queueLogDao.update(queueLog);
        } else {
            queueLogDao.save(queueLog);
        }
    }
}
